package com.qc.bug.Services.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qc.bug.Dao.UserSearchBugMapper;
import com.qc.bug.Services.userSearchBugServices;
import com.qc.bug.pojo.UserInfo;
import com.qc.bug.pojo.UserSearchBug;

@Service
public class userSearchBugServicesImpl implements userSearchBugServices{

	@Autowired
	private UserSearchBugMapper uSearchDao;
	
	/**
	 * 插入用户检索bug信息表信息
	 */
	public int addSearchInfo(int bugId, UserInfo userinfo) {
		UserSearchBug uSearchBug=new UserSearchBug(userinfo.getUserid(),bugId);
		
		return uSearchDao.addSearchInfo(uSearchBug);
	}
	/**
	 * 根据用户ID检索用户查询的BUgId
	 */
	public List<Map<String,Object>> findUserSearchInfo(int userid,int pageIndex,int pageSize) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("userid", userid);
		map.put("index", (pageIndex-1)*pageSize);
		map.put("pageSize", pageSize);
		
		return uSearchDao.findUserSearchInfo(map);
	}
	/**
	 * 获取用户查询的总条数
	 */
	public int getSearchTotal(Integer userid) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("userid", userid);
		return uSearchDao.findSearchTotal(map);
	}
	public int getSearchNumber(int total, int pageSize) {
		if(total%pageSize==0) return total/pageSize;
		return (total/pageSize+1);
	}
	public int deleteBYId(int bugId) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("bugId", bugId);

		return uSearchDao.deleteBYId(map);
		
	}

}
